package com.business.web.spring;


import java.util.List;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.business.domain.T_task_node_instance;
import com.easyworkflow.web.spring.WorkFlowController;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.business.domain.T_building_house;
//import com.business.mapper.T_building_houseMapper;
import com.business.service.T_building_houseService;

@Controller
@RequestMapping("/t_building_house")

public class T_building_houseController extends WorkFlowController{

	private static Logger log = Logger.getLogger(T_building_houseController.class.getName());

	@Resource
    private T_building_houseService t_building_houseService;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	//@Resource
	//private T_building_houseMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_building_house信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_building_house")
	@ResponseBody
	public Pg getAllT_building_house(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_building_house t_building_house = new T_building_house();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_building_house.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("housename")!=null&&!"".equals(request.getParameter("housename"))){
	        	t_building_house.setHousename(request.getParameter("housename"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_building_house.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("buildingname")!=null&&!"".equals(request.getParameter("buildingname"))){
	        	t_building_house.setBuildingname(request.getParameter("buildingname"));
	        }
			if(request.getParameter("buildingtype")!=null&&!"".equals(request.getParameter("buildingtype"))){
	        	t_building_house.setBuildingtype(request.getParameter("buildingtype"));
	        }
			if(request.getParameter("status")!=null&&!"".equals(request.getParameter("status"))){
	        	t_building_house.setStatus(request.getParameter("status"));
	        }
			if(request.getParameter("customername")!=null&&!"".equals(request.getParameter("customername"))){
	        	t_building_house.setCustomername(request.getParameter("customername"));
	        }
			if(request.getParameter("customerid")!=null&&!"".equals(request.getParameter("customerid"))){
	        	t_building_house.setCustomerid(request.getParameter("customerid"));
	        }
			if(request.getParameter("compactstarttime")!=null&&!"".equals(request.getParameter("compactstarttime"))){
	        	t_building_house.setCompactstarttime(request.getParameter("compactstarttime"));
	        }
			if(request.getParameter("compactendtime")!=null&&!"".equals(request.getParameter("compactendtime"))){
	        	t_building_house.setCompactendtime(request.getParameter("compactendtime"));
	        }
			if(request.getParameter("compactsigntime")!=null&&!"".equals(request.getParameter("compactsigntime"))){
	        	t_building_house.setCompactsigntime(request.getParameter("compactsigntime"));
	        }
			if(request.getParameter("fix")!=null&&!"".equals(request.getParameter("fix"))){
	        	t_building_house.setFix(request.getParameter("fix"));
	        }
			if(request.getParameter("applystarttime")!=null&&!"".equals(request.getParameter("applystarttime"))){
	        	t_building_house.setApplystarttime(request.getParameter("applystarttime"));
	        }
			if(request.getParameter("applyendtime")!=null&&!"".equals(request.getParameter("applyendtime"))){
	        	t_building_house.setApplyendtime(request.getParameter("applyendtime"));
	        }
			if(request.getParameter("vr")!=null&&!"".equals(request.getParameter("vr"))){
	        	t_building_house.setVr(request.getParameter("vr"));
	        }
			if(request.getParameter("imagepath")!=null&&!"".equals(request.getParameter("imagepath"))){
	        	t_building_house.setImagepath(request.getParameter("imagepath"));
	        }
			if(request.getParameter("hight")!=null&&!"".equals(request.getParameter("hight"))){
	        	t_building_house.setHight(request.getParameter("hight"));
	        }
			if(request.getParameter("showstatus")!=null&&!"".equals(request.getParameter("showstatus"))){
	        	t_building_house.setShowstatus(request.getParameter("showstatus"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_building_house.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_building_house.setExt3(request.getParameter("ext3"));
	        }
			if(request.getParameter("ext4")!=null&&!"".equals(request.getParameter("ext4"))){
	        	t_building_house.setExt4(request.getParameter("ext4"));
	        }
			if(request.getParameter("ext5")!=null&&!"".equals(request.getParameter("ext5"))){
	        	t_building_house.setExt5(request.getParameter("ext5"));
	        }
			if(request.getParameter("ext6")!=null&&!"".equals(request.getParameter("ext6"))){
	        	t_building_house.setExt6(request.getParameter("ext6"));
	        }
			if(request.getParameter("biztype")!=null&&!"".equals(request.getParameter("biztype"))){
	        	t_building_house.setBiztype(request.getParameter("biztype"));
	        }
      	    if(request.getParameter("houseid")!=null&&!"".equals(request.getParameter("houseid"))){
	        	t_building_house.setHouseid(new Integer(request.getParameter("houseid")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_building_house.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_building_house.setEnddate(request.getParameter("enddate"));
	        }
	        t_building_house.setStartNo( startIndex );
	        t_building_house.setPageSize( pageSize );
	        t_building_house.setEndNo( pageSize );
	    	List<T_building_house> findAll = t_building_houseService.findAll(t_building_house);
	        int totalCount = t_building_houseService.findCountAll(t_building_house);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_building_houseList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_building_houseList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_building_house信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_building_house
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_building_house")
	@ResponseBody
	public JsonVO saveT_building_house(T_building_house t_building_house, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(t_building_houseService.save(t_building_house)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3。1、修改T_building_house信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_building_house
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_building_house")
	@ResponseBody
	public JsonVO updateT_building_house(T_building_house t_building_house, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_building_house t_building_houseTemp = t_building_houseService.findById(t_building_house);
		//t_building_houseTemp.setXXX(t_building_house.getXXX());
		//if(t_building_houseService.update(t_building_houseTemp)){

		if(t_building_houseService.update(t_building_house)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

    /**
     * 3。2、提交审核业务数据
     * 修改T_building_house信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_building_house
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/tjshT_building_house")
    @ResponseBody
    public JsonVO tjshT_company(T_building_house t_building_house, HttpServletRequest request) {
        //启动工作流； 请假流程；
        return startMyTask( getTaskIdByBiztype(t_building_house.getBiztype()),t_building_house.getBiztype(), t_building_house.getHouseid(), request);
    }

    /**
     * 3.3、提交T_building_house审核通过，并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shtgT_building_house")
    @ResponseBody
    public JsonVO shtgT_building_house(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyAgree(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }

    /**
     * 3.4、提交T_building_house审核退回，信息并且返回成功或者失败信息json格式结果如：result:[success/error]
     * @param t_task_node_instance
     * @param request
     * @return JsonVO
     */
    @RequestMapping("/shthT_building_house")
    @ResponseBody
    public JsonVO shthT_building_house(T_task_node_instance t_task_node_instance, HttpServletRequest request) {
        return doMyBack(t_task_node_instance.getTninstanceid(), t_task_node_instance.getNote(), request);
    }
    
	/**
	 * 4、根据id查询T_building_house单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_building_house json格式字符串
	 */
	@RequestMapping("/getT_building_house")
	@ResponseBody
	public T_building_house getT_building_house(Integer id,HttpServletRequest request){
		T_building_house t_building_house = new T_building_house();
		t_building_house.setHouseid(id);
		return t_building_houseService.findById(t_building_house);
	}

	@RequestMapping("/delT__building_houseAllFile")
	@ResponseBody
	public JsonVO delT__building_houseAllFile(Integer id,HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_building_house t_building_house = new T_building_house();
		t_building_house.setHouseid(id);
		t_building_house = t_building_houseService.findById(t_building_house);
		t_building_house.setImagepath("");
		t_building_house.setExt4("");

		if(t_building_houseService.update(t_building_house)>0){
			vo.setResult("success");
			vo.setJieguo(true);
		}
		return vo;
	}
	/**
	 * 5、删除T_building_house根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_building_house")
	@ResponseBody
	public JsonVO delT_building_house(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_building_house t_building_house = new T_building_house();
		t_building_house.setHouseid(id);

		if(t_building_houseService.delete(t_building_house)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_building_house/toT_building_houseList查询所有数据页面
	 *  return /WEB-INF/views/business/t_building_house/t_building_houseList.jsp
	 */
    @RequestMapping(value = "/toT_building_houseList")
    public String toT_building_houseList() {
    	log.debug("------跳转到/WEB-INF/views/business/t_building_house/t_building_houseList.jsp------");
        return "business/t_building_house/t_building_houseList";
    }

	/**
	 * 7、新增、修改、详情页面t_building_house/toT_building_houseCurd跳转
     * business/t_building_house/T_building_houseCurd.jsp
	 */
    @RequestMapping(value = "/toT_building_houseCurd")
    public String toT_building_houseCurd() {
    	log.debug("------跳转到/WEB-INF/views/business/t_building_house/t_building_houseCurd.jsp------");
        return "business/t_building_house/t_building_houseCurd";
    }

    /**
	 * 8、批量删除T_building_house根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_building_houseBatch")
	public String delT_building_houseBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_building_house t_building_house = new T_building_house();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_building_house.setHouseid(new Integer(ids[i]).intValue());
			t_building_houseService.delete(t_building_house);
		}
		if(j==ids.length){
			log.debug("------t_building_house批量删除成功！------");
		}else{
			log.error("------t_building_house批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_building_house/getAllT_building_house";
	}
*/



}









